snippet #!
	#!/usr/bin/python

snippet imp
	import ${1:module}
# Module Docstring
snippet docs
	'''
	File: ${1:`Filename('$1.py', 'foo.py')`}
	Author: ${2:`g:snips_author`}
	Description: ${3}
	'''
snippet wh
	while ${1:condition}:
		${2:# code...}
snippet for
	for ${1:needle} in ${2:haystack}:
		${3:# code...}
# New Class
snippet cl
	class ${1:ClassName}(${2:object}):
		"""${3:docstring for $1}"""
		def __init__(self, ${4:arg}):
			${5:super($1, self).__init__()}
			self.$4 = $4
			${6}
# New Function
snippet def
	def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
		"""${3:docstring for $1}"""
		${4:pass}
snippet deff
	def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
		${3}
# New Method
snippet defs
	def ${1:mname}(self, ${2:arg}):
		${3:pass}
# New Property
snippet property
	def ${1:foo}():
		doc = "${2:The $1 property.}"
		def fget(self):
			${3:return self._$1}
		def fset(self, value):
			${4:self._$1 = value}
# Lambda
snippet ld
	${1:var} = lambda ${2:vars} : ${3:action}
snippet .
	self.
snippet try Try/Except
	try:
		${1:pass}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
snippet try Try/Except/Else
	try:
		${1:pass}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	else:
		${5:pass}
snippet try Try/Except/Finally
	try:
		${1:pass}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	finally:
		${5:pass}
snippet try Try/Except/Else/Finally
	try:
		${1:pass}
	except ${2:Exception}, ${3:e}:
		${4:raise $3}
	else:
		${5:pass}
	finally:
		${6:pass}
# if __name__ == '__main__':
snippet ifmain
	if __name__ == '__main__':
		${1:main()}
# __magic__
snippet _
	__${1:init}__${2}

snippet maintemplate
	#!/usr/bin/env python
	# -*- coding: utf-8 -*-
	"""
	File: ${1:`Filename('$1.py', 'foo.py')`}
	Author: ${2:`g:snips_author`}
	Email: ${3: name@example.com}
	URL: ${4: WebsiteName}
	Version: ${5: 0.1}
	Description: ${6: description of this app}
	"""

	# Base imports
	import sys
	import os
	from optparse import OptionParser
	import logging.handlers
	import ConfigParser

	# Extended imports

	# Global variables
	LOGGING_LEVELS = {"critical": logging.CRITICAL,
					  "error": logging.ERROR,
					  "warning": logging.WARNING,
					  "info": logging.INFO,
					  "debug": logging.DEBUG}

	class ${7:ClassName}(${8:object}):
		"""${9:docstring for $7}"""
		def __init__(self, ${10:arg}):
			# Initialise class wide variables variables
			self.log = logging.getLogger("log")
			self.config = ConfigParser.ConfigParser()
			self.inifile = None
			self.config = None
			self.testing = None
			self.debug = None

			# Get command line arguments.
			dopts = self.getargs()
			# Set command line options
			self.setargs(dopts)

		def usage(self):
			"""Return a string detailing how this program is used."""
			sprogramname = sys.argv[0]
			susage = """
		NAME:
			%s
		SYNOPSIS:
			%s [OPTIONS]
		DESCRIPTION:
			$6
		EXAMPLE:
			python %s 
		""" % \
					(sprogramname, sprogramname, sprogramname)        
			return susage

		def run(self):
			"""The method that starts the program."""
			self.setup()
			self.cleanup()

		def setup(self):
			"""Setup all applicable settings."""

		def getargs(self):
			"""Get program arguments."""
			getoptparser = OptionParser(self.usage())
			getoptparser.add_option("-T", "--testing", action = "store_true", \
									dest = "testing",
									help = "Run in development testing mode.")
			getoptparser.add_option("-D", "--debug", action = "store_true", \
									dest = "debug",
									help = "Run in debug mode. This will print\
									out usefull information.")
			getoptparser.add_option("-l", "--logginglevel", action = "store", \
									type = "string", dest = "logginglevel",
									help = "Logging level")
			getoptparser.add_option("-f", "--loggingfile", action = "store", \
									type = "string", dest = "loggingfile",
									help = "Logging file name")        
			getoptparser.add_option("-i", "--inifile", action = "store", \
									type = "string", dest = "inifile",
									help = "'ini configuration file name for \
									this application.")

			dopts = getoptparser.parse_args()[0]

			return dopts

		def setargs(self, dopts):
			"""Gets all the command line parameters and settings from ini files
			etc and sets up the class wide variables. """
			if not dopts.inifile:
				self.inifile = os.path.join("${11: name of the ini settings file}.ini")
			else:
				self.inifile = dopts.inifile
			self.config.read(self.inifile)

			self.debug = dopts.debug
			self.testing = dopts.testing

			if self.testing != True:
				# In live (non-testing) mode
				if not dopts.loggingfile:
					dopts.loggingfile = os.path.join("$1.log")
				else:
					dopts.loggingfile = os.path.join(dopts.loggingfile)
				logginglevel = LOGGING_LEVELS.get(dopts.logginglevel, \
												  logging.NOTSET)
				logging.basicConfig(level=logginglevel, \
									filename = dopts.loggingfile,
									format = \
									"%(asctime)s %(levelname)s: %(message)s",
									datefmt = "%Y-%m-%d %H:%M:%S")
				emailhandler = logging.handlers.SMTPHandler(
					self.config.get("mailbox", "server"), 
					self.config.get("mailbox", "address"), 
					["${12: loggin emails recipient}"], 
					str(logginglevel) + ": $1"
				)
				emailhandler.setLevel(logging.CRITICAL)
				formatter = logging.Formatter("%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)s")
				emailhandler.setFormatter(formatter)
				self.log.addHandler(emailhandler)
			else:
				# In testing (non-live) mode
				logginglevel = LOGGING_LEVELS.get("debug", logging.NOTSET)
				logging.basicConfig(level=logginglevel, filemode = "w", \
									filename = os.path.join("debug.log"),
									format = \
									"%(asctime)s %(levelname)s: %(message)s",
									datefmt = "%Y-%m-%d %H:%M:%S")

		def cleanup(self):
			"""Cleans up any variables etc."""
			
	if __name__ == "__main__":
		program = $7()
		program.run()
